'''
Created on 17/10/2011

@author: nacho
'''

class Scheduler(object):
    '''
    classdocs
    '''


    def __init__(self, planification):
        '''
        Constructor
        '''
        self.plan = planification
        
        
    def setOS(self, so):
        
        self.kernel = so
        
    def fullRunning(self, pid, cpu):
        

        cpu.fullRun(pid)
        
        #self.kernel.changeStateToRunning(pid)
        
    
    def calculatePriority(self):
        
        pid = self.kernel.calculatePriority()
        if pid is None:
            self.kernel.stopRunning()
        else:    
            return pid
        
    def reschedule(self, cpu):
        
        self.plan.reschedule(self,cpu)

        
    def changeState(self,pid):
        
        self.os.changeStateToReady(pid)
        
        
    def runPCB(self, pid, cpu):
        
        #self.kernel.loadToMemory(pid)
        inumber = self.kernel.instrNumber(pid)
        cpu.runPCB(pid, inumber)
        
    def click (self,so,readyQ):
        
        self.plan.click(so,readyQ)
        
    def firstPID(self):
        
        return self.kernel.firstPID()
    
    def choosePidToLoad(self):
        
        return self.plan.choosePidToLoad(self.kernel)
        
    def deserveMemory(self, pid, so):
        
        self.plan.deserveMemory(pid, so)